#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Software : PyCharm
# @Time    : 2025-01-20 10:13
# @Author  : gzh
# @File : TkModel.py

from tkinter import Canvas
from . import _Tks
from PIL import ImageTk

class TkModel(Canvas):
    def __init__(self):
        super().__init__(_Tks)
        self.parent = _Tks
        self.image = None
        self.image_c = None
        self.bind("<Configure>", lambda event: self._draw())
        self.pack(fill='both', expand=True)

        # for i in ('f30', 'f25', 'f22', 'f18', 'f15', 'f13', 'f20'):
        #     self.__dict__[i] = self.parent.__dict__[i]
        self.f30 = self.parent.f30
        self.f25 = self.parent.f25
        self.f22 = self.parent.f22
        self.f20 = self.parent.f20
        self.f18 = self.parent.f18
        self.f15 = self.parent.f15
        self.f13 = self.parent.f13


    def _draw(self):
        width, height = self.winfo_width(), self.winfo_height()
        self.delete('pl')
        if self.image is not None:
            self.image_c = self.image.resize((width, height))
            self.image_c = ImageTk.PhotoImage(self.image_c)
            self.create_image(width*0.5, height*0.5, image=self.image_c, tags='pl')
        return width, height
